#pragma once 

#include <iostream>
#include <pthread.h>

class Mutex
{
public:
    Mutex(pthread_mutex_t *p_mtx)
        : _p_mtx(p_mtx)
    { }

    void lock()
    {
        pthread_mutex_lock(_p_mtx);
    }

    void unlock()
    {
        pthread_mutex_unlock(_p_mtx);
    }

private:
    pthread_mutex_t *_p_mtx;
};


class LockGuard
{
public:
    LockGuard(pthread_mutex_t *p_mtx)
        : _mtx(p_mtx)
    {
        _mtx.lock();
    }

    ~LockGuard()
    {
        _mtx.unlock();
    }

private:
    Mutex _mtx;
};